<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
          
 
<form class="layui-form" action="" lay-filter="example" style="margin-top:10px">
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入用户名" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-inline">
      <select name="status" lay-filter="aihao">
        <option value="1" selected="selected">正常</option>
        <option value="2">冻结</option>
        <option value="3">待激活</option>
      </select>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">性别</label>
    <div class="layui-input-inline">
      <input type="radio" name="sex" value="1" title="男" checked="">
      <input type="radio" name="sex" value="2" title="女">
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-inline">
      <textarea placeholder="请输入内容" class="layui-textarea" name="remark"></textarea>
    </div>
  </div>
 
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
    </div>
  </div>
</form>
          
<script src="/static/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form'], function(){
  var form = layui.form;
  var $ = layui.$;
  
  form.on('submit(demo1)',function(data){
	  alert(data.username);
	  $.ajax({
		  url:'/user/save',
		  method:'post',
		  data:data.field,
		  dataType:'JSON',
		  success:function(res){
			  if(res.code==0){
				  layer.msg('添加成功',{
					  icon:1,
					  time:2000
				  },function(){
					  //刷新数据
					  parent.layui.table.reload('testReload',{page:{curr:1}});
					  parent.layer.closeAll();
				  });
			  }else{
				  layer.msg(res.msg,{
					  icon:2,
					  time:1500
				  },function(){
					  
				  });
			  }
		  }
	  });
	  return false;
  })
  
  //表单取值
  layui.$('#LAY-component-form-getval').on('click', function(){
    var data = form.val('example');
    alert(JSON.stringify(data));
  });
  
  
  
});
</script>

</body>
</html>
